//
//  NSVipItemView.m
//  Meboo
//
//  Created by kyo on 2024/4/29.
//

#import "NSVipItemView.h"

@interface NSVipItemView ()
@property (nonatomic, strong) UIImageView *stateImageView;
@property (nonatomic, strong) UILabel *NumLab;
@property (nonatomic, strong) UILabel *dateLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *stateLab;
@end

@implementation NSVipItemView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd

- (void)setModel:(NSProductModel *)model {
    _model = model;
    self.NumLab.text = model.UINum;
    self.dateLab.text = model.benefitUnit;
    self.priceLab.text = [NSString stringWithFormat:@"$ %@",model.price];
    self.stateLab.text = model.tip;
    if (model.isSelect) {
        self.stateImageView.image = ImageWithName(@"mine_vip_type_state_select");
        self.layer.borderWidth = 2;
        self.layer.borderColor = HEXS(@"6F29B6").CGColor;
        self.NumLab.textColor = HEXS(@"6F29B6");
        self.dateLab.textColor = HEXS(@"6F29B6");
        self.priceLab.textColor = HEXS(@"6F29B6");
    } else {
        self.stateImageView.image = ImageWithName(@"mine_vip_type_state_normal");
        self.layer.borderWidth = 1;
        self.layer.borderColor = HEXS(@"DDDDDD").CGColor;
        self.NumLab.textColor = HEXS(@"666666");
        self.dateLab.textColor = HEXS(@"666666");
        self.priceLab.textColor = HEXS(@"666666");
    }
    if (model.tip.length == 0) {
        self.stateImageView.hidden = YES;
    } else {
        self.stateImageView.hidden = NO;
    }
}

- (void)setIndex:(NSInteger)index {
    _index = index;
    NSString *numStr = @"1";
    NSString *dateStr = @"Week";
    NSString *priceStr = @"$ 19.99";
    NSString *tipStr = @"";
    if (index == 0) {
        numStr = @"1";
        dateStr = @"Week";
        priceStr = @"$ 19.99";
        tipStr = @"";
        self.stateImageView.hidden = YES;
    } else if (index == 1) {
        numStr = @"1";
        dateStr = @"Month";
        priceStr = @"$ 29.99";
        tipStr = @"Popular";
        self.stateImageView.hidden = NO;
    } else {
        numStr = @"3";
        dateStr = @"Months";
        priceStr = @"$ 59.99";
        tipStr = @"Preferential";
        self.stateImageView.hidden = NO;
    }
    
    self.NumLab.text = numStr;
    self.dateLab.text = dateStr;
    self.priceLab.text = priceStr;
    self.stateLab.text = tipStr;
    
    if (index == 1) {
        self.stateImageView.image = ImageWithName(@"mine_vip_type_state_select");
        self.layer.borderWidth = 2;
        self.layer.borderColor = HEXS(@"6F29B6").CGColor;
        self.NumLab.textColor = HEXS(@"6F29B6");
        self.dateLab.textColor = HEXS(@"6F29B6");
        self.priceLab.textColor = HEXS(@"6F29B6");
    } else {
        self.stateImageView.image = ImageWithName(@"mine_vip_type_state_normal");
        self.layer.borderWidth = 1;
        self.layer.borderColor = HEXS(@"DDDDDD").CGColor;
        self.NumLab.textColor = HEXS(@"666666");
        self.dateLab.textColor = HEXS(@"666666");
        self.priceLab.textColor = HEXS(@"666666");
    }
}

#pragma mark - Action
- (void)clickItem {
    if (self.clickBlock) {
        self.clickBlock(self.tag);
    }
}

#pragma mark - UI
- (void)setupUI {
    
    UITapGestureRecognizer *actionTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickItem)];
    [self addGestureRecognizer:actionTap];
    
    self.backgroundColor = UIColor.whiteColor;
    self.layer.cornerRadius = MBHeightScale(10);
    
    self.layer.borderColor = HEXS(@"B92176").CGColor;
    self.layer.borderWidth = 0;
    self.layer.masksToBounds = YES;
    
    [self addSubview:self.dateLab];
    [self.dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.mas_equalTo(MBHeightScale(10));
    }];
    
    [self addSubview:self.NumLab];
    [self.NumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.dateLab.mas_top).offset(MBHeightScale(-6));
    }];
    
    [self addSubview:self.priceLab];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.dateLab.mas_bottom).offset(MBHeightScale(6));
    }];
    
    [self addSubview:self.stateImageView];
    [self.stateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.top.equalTo(self);
    }];
    
    [self.stateImageView addSubview:self.stateLab];
    [self.stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.top.equalTo(self.stateImageView);
        make.left.mas_equalTo(MBWidthScale(10));
    }];
}

#pragma mark - Setter && Getter

- (UILabel *)NumLab {
    if (!_NumLab) {
        _NumLab = [[UILabel alloc] init];
        _NumLab.textAlignment = NSTextAlignmentCenter;
        _NumLab.font = MBHelBoldFontSizeScale(28);
        _NumLab.textColor = HEXS(@"666666");
    }
    return _NumLab;
}

- (UILabel *)dateLab {
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.textAlignment = NSTextAlignmentCenter;
        _dateLab.font = MBHelFontSizeScale(16);
        _dateLab.textColor = HEXS(@"666666");
    }
    return _dateLab;
}

- (UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] init];
        _priceLab.textAlignment = NSTextAlignmentCenter;
        _priceLab.font = MBHelBoldFontSizeScale(16);
        _priceLab.textColor = HEXS(@"666666");
    }
    return _priceLab;
}

- (UIImageView *)stateImageView {
    if (!_stateImageView) {
        _stateImageView = [UIImageView new];
        _stateImageView.hidden = YES;
        _stateImageView.image = ImageWithName(@"mine_vip_type_state_normal");
    }
    return _stateImageView;
}

- (UILabel *)stateLab {
    if (!_stateLab) {
        _stateLab = [[UILabel alloc] init];
        _stateLab.textAlignment = NSTextAlignmentCenter;
        _stateLab.font = MBHelFontSizeScale(12);
        _stateLab.textColor = HEXS(@"ffffff");
    }
    return _stateLab;
}
@end

